<?php
/**
 * 问答社区消息控制器
 */
class Commwapnotify extends Base_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->load->model('commwap_model');
    }

    public function getUserNotify()
    {
        $uid = $this->input->post('uid');
        if (!isset($uid)||!is_numeric($uid)) $this->error('lack uid');
        $pagesize = $this->input->post('pagesize');
        if (!isset($pagesize)||!is_numeric($pagesize)) $limit = 10;
        else $limit = (int)$pagesize;
        $page = $this->input->post('page');
        if (isset($page)&&is_numeric($page)&&$page>0) $start = ((int)$page-1)*$limit;
        else $start = 0;
        $end = $start+$limit-1;

        $res = $this->commwap_model->getUserNotify($uid,$start,$end,$limit);
        $this->success($res);

    }
    public function getNotifyUnread()
    {
        $uid = $this->input->post('uid');
        if (!isset($uid)||!is_numeric($uid)) $this->error('lack uid');

        $res = $this->commwap_model->getNotifyUnread($uid);
        $this->success($res);
    }
    public function getSysnotify()
    {
        $uid = $this->input->post('uid');
        if (!isset($uid)||!is_numeric($uid)) $this->error('lack uid');
        $pagesize = $this->input->post('pagesize');
        if (!isset($pagesize)||!is_numeric($pagesize)) $limit = 10;
        else $limit = (int)$pagesize;
        $page = $this->input->post('page');
        if (isset($page)&&is_numeric($page)&&$page>0) $start = ((int)$page-1)*$limit;
        else $start = 0;
        $end = $start+$limit-1;

        $res = $this->commwap_model->getSysnotify($uid,$start,$end,$limit);
        $this->success($res);
    }
    public function readNotify()
    {
        $uid = $this->input->post('uid');
        if (!isset($uid)||!is_numeric($uid)) $this->error('lack uid');
        $msgid = $this->input->post('msgid');
        if (!isset($msgid)) $this->error('lack msgid');
        $msgtype = $this->input->post('msgtype');
        if (!isset($msgtype)) $this->error('lack msgtype');

        $this->commwap_model->readNotify($uid,$msgid,$msgtype);
        $this->success();
    }
    public function clearNotify()
    {
        $uid = $this->input->post('uid');
        if (!isset($uid)||!is_numeric($uid)) $this->error('lack uid');
        $this->commwap_model->clearNotify($uid);
        $this->success();
    }

}